package com.app.acitivty;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

import com.app.activity.R;
import com.app.components.TopMenu;
import com.app.data.DataGeneration;
import com.app.data.InnItem;
import com.app.data.LineItem;
import com.app.data.ListDataModel;
import com.app.data.ScenicItem;
import com.app.data.TicketItem;
import com.app.utils.ActivityTools;

/**
 * 已经购买
 * 
 * @author Administrator
 * 
 */
public class BoughtListActivity extends Activity {

	private LineItem[] lineitems=
		{
			new LineItem(R.drawable.line1, "丽江泸沽湖旅游 泸沽湖纯玩 金沙江二日游 摩梭民俗花楼恋歌 ", "出发时间：2012-06-01", "￥455起"), 
			new LineItem(R.drawable.line2, "云南丽江 泸沽湖 女儿国 婚俗游民俗特色三日游 体验走婚 纯玩团", "出发时间：2012-06-01", "￥718起"), 
			new LineItem(R.drawable.line3, "云南丽江旅游 泸沽湖 走婚族 纯玩三日 猪糟船 花楼恋歌 摩梭特色", "出发时间：2012-06-01", "￥780起"), 
			new LineItem(R.drawable.line4, "云南丽江旅游 玉龙雪山 牦牛坪一日游 含古维牦牛坪索道 印象丽江", "出发时间：2012-06-01", "￥455起"), 
			new LineItem(R.drawable.line1, "丽江泸沽湖旅游 泸沽湖纯玩 金沙江二日游 摩梭民俗花楼恋歌 ","出发时间：2012-06-01", "￥455起"), 
			new LineItem(R.drawable.line2, "云南丽江 泸沽湖 女儿国 婚俗游民俗特色三日游 体验走婚 纯玩团", "出发时间：2012-06-01", "￥718起"), 
			new LineItem(R.drawable.line3, "云南丽江旅游 泸沽湖 走婚族 纯玩三日 猪糟船 花楼恋歌 摩梭特色", "出发时间：2012-06-01", "￥780起")
		};
	
	private Button[] btns = new Button[4];

	private ListView[] listviewList = new ListView[4];

	private void initView() {

		btns[0] = (Button) findViewById(R.id.btnPassengerTicket);
		btns[1] = (Button) findViewById(R.id.btnInn);
		btns[2] = (Button) findViewById(R.id.btnTickets);
		btns[3] = (Button) findViewById(R.id.btnLine);
		listviewList[0] = (ListView) findViewById(R.id.lvTicketList);
		listviewList[1] = (ListView) findViewById(R.id.lvInnList);
		listviewList[2] = (ListView) findViewById(R.id.lvScenicList);
		listviewList[3] = (ListView) findViewById(R.id.lvLineList);
		
		listviewList[0].setOnItemClickListener(
				new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> arg0, View view,
							int postion, long arg3) {
						ActivityTools.gotoActivity(BoughtListActivity.this, TicketDetailActivity.class);
					}
		});
		
		listviewList[1].setOnItemClickListener(
				new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> arg0, View view,
							int postion, long arg3) {
						ActivityTools.gotoActivity(BoughtListActivity.this, InnDetailActivity.class);
					}
		});
		
		listviewList[2].setOnItemClickListener(
				new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> arg0, View view,
							int postion, long arg3) {
						ActivityTools.gotoActivity(BoughtListActivity.this, ScenicDetailActivity.class);
					}
		});
		
		listviewList[3].setOnItemClickListener(
				new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> arg0, View view,
							int postion, long arg3) {
						ActivityTools.gotoActivity(BoughtListActivity.this, LineDetailActivity.class);
					}
		});
		
	}

	
	private ArrayList<HashMap<String, String>> mLineListItems = null;

	private String[] mLineColumnNames = { "lineIcon", "lineName",
			"lineTransport", "linePrice" };

	private int[] mLineViewIds = { R.id.imgLineIcon, R.id.tvLineName,
			R.id.tvLineTransport, R.id.tvLinePrice };
	private ArrayList<HashMap<String, String>> mInnListItems = null;

	private String[] mInnColumnNames = { "innIcon", "innName", "innAddress",
			"innStarLevel", "innPrice" };

	private int[] mInnViewIds = { R.id.imgInnIcon, R.id.tvInnName,
			R.id.tvInnAddress, R.id.imgInnStarLevel, R.id.tvInnPrice };

	private ArrayList<HashMap<String, String>> mScenicItems = null;
	private String[] mScenicColumnNames = { "scenicIcon", "senicName",
			"senicPrice", "senicIntro", "senicSubject" };

	private int[] mScenicViewIds = { R.id.imgScenicIcon, R.id.tvSenicName,
			R.id.tvSenicPrice, R.id.tvSenicIntro, R.id.tvSenicSubject };

	private ArrayList<HashMap<String, String>> mItems = null;

	private String[] mTicketColumnNames = { "ticketTitle", "ticketPrice",
			"ticketStart", "ticketEnd" };

	private int[] mTicketViewIds = { R.id.tickt_item_title,
			R.id.tickt_item_price, R.id.tickt_item_start, R.id.tickt_item_end };

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bought_list);
		initView();

		TopMenu topMenu = new TopMenu(this, "返回", new OnClickListener() {

			@Override
			public void onClick(View v) {
				BoughtListActivity.this.finish();

			}
		}, R.drawable.top_button_unselect, R.drawable.top_button_selected, "已购");
		topMenu.onCreate();

		DisplayMetrics metric = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metric);
		int btnWidth = metric.widthPixels / 4;


		// 加入高亮显示效果
		for (int i = 0; i < btns.length; i++) {			
			LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) btns[i].getLayoutParams(); 
			linearParams.width=btnWidth;
			this.changeButtonState(i);
		}
		
		listviewList[0].setVisibility(View.INVISIBLE);

		// 机票列表
		mItems = new ArrayList<HashMap<String, String>>();

		for (int i = 0; i < 4; i++) {
			TicketItem ti = new TicketItem();
			ti.setTicketTitle("中国国航VA1854");
			ti.setTicketPrice("宁波的什么机场8点起飞");
			ti.setTicketStart("丽江的什么机场10点到达");
			ti.setTicketEnd("￥1033起");
			mItems.add(TicketListActivity.addItem(ti));
		}

		ListAdapter laTicket = new SimpleAdapter(this, mItems,
				R.layout.ticket_list_item, mTicketColumnNames, mTicketViewIds);
		listviewList[0].setAdapter(laTicket);

		// 客栈列表

		ArrayList<ListDataModel> detailItems = DataGeneration
				.getHotelTestInfo(5);

		int len = detailItems.size();

		mInnListItems = new ArrayList<HashMap<String, String>>();

		for (int i = 0; i < 3; i++) {
			mInnListItems.add(InnListSearchActivity.addItem((InnItem) detailItems.get(i)));
		}

		ListAdapter laInn = new SimpleAdapter(this, mInnListItems,
				R.layout.inn_list_item, mInnColumnNames, mInnViewIds);

		listviewList[1].setAdapter(laInn);

		// 景点列表

		mScenicItems = new ArrayList<HashMap<String, String>>();

		for (int i = 0; i < 2; i++) {
			ScenicItem si = new ScenicItem();
			si.setScenicIcon(R.drawable.scen_logo);
			si.setSenicName("丽江虎跳峡");
			si.setSenicPrice("￥133起");
			si.setSenicIntro("虎跳峡,中国最深的峡谷之一，在云南省玉龙纳西族自治县...");
			si.setSenicSubject("主题：生态旅游  休闲  生态旅游");
			mScenicItems.add(ScenicSearchListActivity.addItem(si));
		}

		ListAdapter lamScenic = new SimpleAdapter(this, mScenicItems,
				R.layout.scenic_list_item, mScenicColumnNames, mScenicViewIds);

		listviewList[2].setAdapter(lamScenic);

		// 线路列表
		
		mLineListItems = new ArrayList<HashMap<String, String>>();

		for (int i = 0; i < 7; i++) {
			LineItem li = lineitems[i];
//			li.setLineIcon(R.drawable.line_logo);
//			li.setLineName("上海到昆明 大理 丽江&lt;完美云南> 双飞六日游 HX3");
//			li.setLinePrice("￥2022起");
//			li.setLineTransport("交通：飞机来飞机去");
			mLineListItems.add(LineListActivity.addItem(li));
		}

		ListAdapter laLine = new SimpleAdapter(this, mLineListItems,
				R.layout.line_list_item, mLineColumnNames, mLineViewIds);

		listviewList[3].setAdapter(laLine);

	}

	private void changeButtonState(final int buttonid) {

		btns[buttonid].setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_DOWN) {
					for (int i = 0; i < btns.length; i++) {
						if (buttonid == i) {
							btns[buttonid]
									.setBackgroundResource(R.drawable.tab_active);
							// 切换页面
							listviewList[i].setVisibility(View.INVISIBLE);
						} else {
							btns[i].setBackgroundResource(R.drawable.tab_normal);
							listviewList[i].setVisibility(View.GONE);
						}
					}
				}
				return false;
			}

		});

	}

}
